﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
    class GameplayState : BaseState
    {
        Texture2D m_texBackGround;
        Texture2D m_texGround;
        Camera m_Camera = new Camera();

        ContentManager Content;

        public GameplayState(Game1 _game)
        {
            Content = new ContentManager(_game.Services, "Content");
        }

        KeyboardState m_LastKeyState;

        public void Enter()
        {
            Content.RootDirectory = "Content";
            m_texBackGround = Content.Load<Texture2D>("background");
            m_texGround = Content.Load<Texture2D>("ground");

            Player tempPlayer = new Player();
            tempPlayer.m_Texture = Content.Load<Texture2D>("trywalk");
            tempPlayer.m_Position = new Vector2(100, 100);
            m_Camera.m_Target = tempPlayer;


            Equip tempHair = new Equip();
            tempHair.m_Texture = Content.Load<Texture2D>("Equips/Hair/Hair001");
            tempHair.m_cColor = Color.Green;
            tempPlayer.m_lEquips.Add(tempHair);

            Equip tempChest = new Equip();
            tempChest.m_Texture = Content.Load<Texture2D>("Equips/Chest/Chest001");
            tempChest.m_cColor = Color.LightBlue;
            tempPlayer.m_lEquips.Add(tempChest);

            Equip tempShoulder = new Equip();
            tempShoulder.m_Texture = Content.Load<Texture2D>("Equips/Shoulder/Shoulder001");
            tempShoulder.m_cColor = Color.DarkKhaki;
            tempPlayer.m_lEquips.Add(tempShoulder);

            Equip tempWeapon = new Equip();
            tempWeapon.m_Texture = Content.Load<Texture2D>("Equips/Weapon/Weapon001");
            tempWeapon.m_cColor = Color.Silver;
            tempPlayer.m_lEquips.Add(tempWeapon);

            ObjectManager.m_ObjectManager.m_ObjectList.Add(tempPlayer);

            Monster tempMonster = new Monster();
            tempMonster.m_Texture = Content.Load<Texture2D>("rock");
            ObjectManager.m_ObjectManager.m_ObjectList.Add(tempMonster);
        }

        public void Exit()
        {
            Content.Unload();
        }

        public void Update(float _delta)
        {
            ObjectManager.m_ObjectManager.Update(_delta, m_LastKeyState);

            m_Camera.Update(_delta);

            m_LastKeyState = Keyboard.GetState();
        }

        public void Render(SpriteBatch _spriteBatch)
        {
            _spriteBatch.Draw(m_texGround, new Rectangle((int)((0 - m_Camera.m_Position.X) * m_Camera.m_fZoom),
                (int)((12 - m_Camera.m_Position.Y) * m_Camera.m_fZoom), (int)(800 * m_Camera.m_fZoom),
                (int)(600 * m_Camera.m_fZoom)), Color.White);
            ObjectManager.m_ObjectManager.Render(_spriteBatch, m_Camera);
        }

    }
}
